package com.jinkaimen.kqb.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.BaseAdapter;

import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseRefreshListViewFragment;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.ht.baselibs.utils.UIUtils;
import com.jinkaimen.kqb.bean.ReportShoperManagerBean;
import com.jinkaimen.kqb.bean.ReportShoperManagerItemBean;
import com.jinkaimen.kqb.constant.ConstantPool;
import com.jinkaimen.kqb.manager.ApiManager;
import com.jinkaimen.kqb.ui.activity.addmerchant.IdentificationShopStep1Activity;
import com.jinkaimen.kqb.ui.adapter.WaitPassShoperAdapter;

import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

public class NotPassShoperManagerFragment extends BaseRefreshListViewFragment<ReportShoperManagerItemBean> {

    private int mCurrentPage;

    @Override
    protected View getHeaderView() {
        return null;
    }

    @Override
    protected void initChildDataFromCache() {

    }

    @Override
    protected BaseAdapter getAdapter() {
        return new WaitPassShoperAdapter(mContext, mDataList, 1);
    }

    @Override
    protected void loadData() {
        mCurrentPage = 1;
        ApiManager.getApi().reportShoperManager(
                "INV_HSY001012",
                SharedPreferencesUtils.getLong(ConstantPool.REPORT_ACCOUT_ID, 0),
                mCurrentPage,
                3,
                1
        ).enqueue(new NetCallBack<ReportShoperManagerBean>() {
            @Override
            protected void onSuccess(Call<ReportShoperManagerBean> call, Response<ReportShoperManagerBean> response) {
                mDataList.clear();
                mDataList.addAll(response.body().list);
                onRefreshCompleteSuccess();
            }

            @Override
            public void onFailure(Call<ReportShoperManagerBean> call, Throwable t) {
                super.onFailure(call, t);
                onRefreshCompleteError();
            }
        });
    }

    @Override
    protected void onLoadMore() {
        mCurrentPage++;
        ApiManager.getApi().reportShoperManager(
                "INV_HSY001012",
                SharedPreferencesUtils.getLong(ConstantPool.REPORT_ACCOUT_ID, 0),
                mCurrentPage,
                3,
                1
        ).enqueue(new NetCallBack<ReportShoperManagerBean>() {
            @Override
            protected void onSuccess(Call<ReportShoperManagerBean> call, Response<ReportShoperManagerBean> response) {
                List<ReportShoperManagerItemBean> list = response.body().list;

                if (list.size() > 0){
                    mDataList.addAll(list);
                } else {
                    UIUtils.showToast("没有更多数据");
                }

                onLoadMoreComplete();
            }

            @Override
            public void onFailure(Call<ReportShoperManagerBean> call, Throwable t) {
                super.onFailure(call, t);
                onLoadMoreComplete();
            }
        });
    }

    @Override
    public void onItemClickInner(int position) {
        ReportShoperManagerItemBean reportShoperManagerItemBean = mDataList.get(position);
        Bundle bundle = new Bundle();
        bundle.putLong("report_account_id", reportShoperManagerItemBean.uid);
        bundle.putLong("report_shop_id", reportShoperManagerItemBean.id);
        ActivityUtils.startActivityAndFinish(mContext, IdentificationShopStep1Activity.class, bundle);
    }

}